﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;

public partial class CMS_Admin_block_VoteConfirm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void OK_Click(object sender, EventArgs e)
    {
        Usas.Common.Cms.CurrentInfo cinfo = new Usas.Common.Cms.CurrentInfo();
        Usas.BLL.Cms.cms_vote_result cvr = new Usas.BLL.Cms.cms_vote_result();
        Usas.Model.Cms.cms_vote_result cvrm = new Usas.Model.Cms.cms_vote_result();

        Usas.BLL.Cms.cms_block_common_detail_option cop = new Usas.BLL.Cms.cms_block_common_detail_option();
        Usas.Model.Cms.cms_block_common_detail_option copm = new Usas.Model.Cms.cms_block_common_detail_option();

        int cid = Convert.ToInt32(Request["cid"]);
        string[] oid = Request["oid"].ToString().Substring(0, Request["oid"].ToString().Length - 1).Split(',');

        for (int i = 0; i < oid.Length; i++)
        {
            Regex m_regex = new System.Text.RegularExpressions.Regex("^(-?[0-9]*[.]*[0-9]{0,3})$");
            if (m_regex.IsMatch(oid[i]))
            {
                cvrm.v_c_id = Convert.ToInt32(cid);
                cvrm.v_o_id = Convert.ToInt32(oid[i]);
                cvrm.v_eid = Convert.ToInt32(cinfo.GetEmpId());
                cvrm.v_value = "1";
                int rid = cvr.Add(cvrm);

                copm = cop.GetModel(cvrm.v_o_id);
                copm.o_value = Convert.ToString(Convert.ToInt32(copm.o_value) + 1);
                cop.Update(copm);
            }
        }

        OK.Visible = false;
        ctt.InnerHtml = "投票成功！<br/>转向中 ...请稍等";
        ClientScript.RegisterStartupScript(GetType(), "Msg", "parent.location.href='" +
            Server.UrlDecode(Request["url"]) + "'", true);

    }
}
